package com.youku.plugins.controlbarV4.view.components
{
   import flash.display.Sprite;
   import flash.text.TextField;
   import flash.text.TextFormat;
   import com.youku.utils.BaseUtil;
   import com.youku.plugins.controlbarV4.ControlBarConstant;
   import flash.events.MouseEvent;
   
   public class TimeDisplayer extends Sprite
   {
      
      public function TimeDisplayer() {
         super();
         this.init();
      }
      
      protected var _timeText:TextField;
      
      protected var _timeFormatLight:TextFormat;
      
      protected var _shortMode:Boolean;
      
      protected var _countMode:Boolean;
      
      protected var _currentTime:Number;
      
      protected var _totalTime:Number;
      
      protected var _span:Number = 30;
      
      private function init() : void {
         this._timeFormatLight = new TextFormat();
         this._timeFormatLight.font = "Arial";
         this._timeFormatLight.size = 14;
         this._timeFormatLight.color = 5592405;
         this._timeText = new TextField();
         this._timeText.defaultTextFormat = this._timeFormatLight;
         this._timeText.width = this.width;
         this._timeText.height = 24;
         this._timeText.selectable = false;
         addChild(this._timeText);
         this._timeText.y = 10;
      }
      
      public function setTimeText(param1:Number, param2:Number) : void {
         this._currentTime = param1;
         this._totalTime = param2;
         var _loc3_:* = "";
         if(this._shortMode)
         {
            if(this._countMode)
            {
               _loc3_ = "-" + BaseUtil.formatTime(this._totalTime - this._currentTime);
            }
            else
            {
               _loc3_ = BaseUtil.formatTime(this._currentTime);
            }
         }
         else
         {
            _loc3_ = BaseUtil.formatTime(param1) + " / " + BaseUtil.formatTime(param2);
         }
         this._timeText.text = _loc3_;
      }
      
      override public function get width() : Number {
         var _loc1_:* = NaN;
         if(this._shortMode)
         {
            _loc1_ = 50 + this._span;
         }
         else
         {
            _loc1_ = 95 + this._span;
         }
         this._timeText.width = _loc1_;
         return _loc1_;
      }
      
      public function setStyle(param1:String) : void {
         switch(param1)
         {
            case ControlBarConstant.CONTROLBAR_STYLE_LIGHT:
               this._timeFormatLight.color = 5592405;
               break;
            case ControlBarConstant.CONTROLBAR_STYLE_DARK:
               this._timeFormatLight.color = 12303291;
               break;
         }
         this._timeText.defaultTextFormat = this._timeFormatLight;
         this._timeText.text = this._timeText.text;
      }
      
      public function set shortMode(param1:Boolean) : void {
         this._shortMode = param1;
         this.mouseEnabled = this._shortMode;
         this.buttonMode = this._shortMode;
         this._timeText.width = this.width - this._span;
         if(this._shortMode)
         {
            this.addEventListener(MouseEvent.CLICK,this.onClick);
         }
         else
         {
            this.removeEventListener(MouseEvent.CLICK,this.onClick);
         }
         this.setTimeText(this._currentTime,this._totalTime);
      }
      
      private function onClick(param1:MouseEvent) : void {
         this._countMode = !this._countMode;
      }
   }
}
